<!DOCTYPE html>
<html>
{include file="public/header" /}
<body>
<div class="layui-fluid" id="app">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">

                <ul class="layui-tab-title">
                    <li onclick="go('project_worker?id='+'{$Request.param.id}')">施工</li>
                    <li onclick="location.reload()" class="layui-this">竞标管理</li>
                </ul>
                <div class="layui-tab-content" style="padding-left: 0px;padding-right: 0px">
                    <div class="layui-tab-item layui-show">
                        <div class="layui-row">
                            <div class="layui-col-md12" style="margin-top: 10px">
                                <fieldset class="layui-elem-field">
                                    <legend>工种</legend>
                                    <div class="layui-field-box">
                                        <div class="layui-row">
                                            {foreach name="types" item="data"}
                                            <div class="layui-col-md12" style="height: 35px;font-size: 18px">
                                                <div class="layui-row layui-col-space15">
                                                            <span class="layui-col-md4">
                                                                 <span>工种：</span>
                                                                 <span>{$data.type}</span>
                                                            </span>
                                                    <span class="layui-col-md4">
                                                                 <span>工价：</span>
                                                                 <span>{$data.pricet}￥</span>
                                                            </span>
                                                </div>

                                            </div>
                                            {/foreach}
                                        </div>
                                    </div>
                                </fieldset>
                            </div>
                            <div class="layui-col-md12" style="margin-top: 10px">
                                <fieldset class="layui-elem-field layui-field-title">
                                    <legend>竞标管理</legend>
                                    <div class="layui-field-box">
                                        <table class="layui-table" lay-skin="line">

                                            <thead>
                                            <tr>
                                                <th>头像</th>
                                                <th>姓名</th>
                                                <th>工种</th>
                                                <th>电话</th>
                                                <th></th>
                                                <th style="width: 20%"></th>
                                            </tr>
                                            </thead>
                                            <tbody>
                                            <tr v-for="(item,index) in items" :data_id="item.id">
                                                <td>
                                                    <img v-if="item.avatar2=='0'" src="/res/img/thumb.png"
                                                         style="max-width: 50px;">
                                                    <img v-else :src="item.avatar2" style="max-width: 50px;">
                                                </td>
                                                <td>{{item.truename}}</td>
                                                <td>{{item.gongzhong}}</td>
                                                <td>{{item.phone}}</td>
                                                <td>
                                                    <i v-if="item.status==1" class="layui-icon"
                                                       style="font-size: 20px; color:red;">&#xe605;</i>
                                                    <i v-if="item.status==2" class="layui-icon"
                                                       style="font-size: 20px; color:red;">&#x1006;</i>
                                                    <i v-else></i>
                                                </td>
                                                <td>
                                                    <div class="layui-btn-group">
                                                        <button class="layui-btn layui-btn-sm layui-btn-primary"
                                                                :worker_id="item.worker_id" :data_id="item.id"
                                                                onclick="agree(this)">同意
                                                        </button>
                                                        <button class="layui-btn layui-btn-sm layui-btn-primary"
                                                                onclick="refuse(this)" :data_id="item.id">拒绝

                                                        </button>
                                                    </div>
                                                </td>

                                            </tr>

                                            </tbody>
                                        </table>
                                        <div id="demo7"></div>
                                    </div>
                                </fieldset>
                            </div>
                        </div>
                    </div>

                </div>
            </div>
        </div>


    </div>
</div>


<script>


    //vue对象
    var app = new Vue({
        el: '#app',
        data: {
            curr: 1,
            limit: 6,
            items: [],
            list: [],

        },
    });

    console.log(app.its);

    function init() {
        layer.load(2);
        $.get("{:url('bid')}", {page: app.curr, limit: app.limit, id: "{$Request.param.id}"},
            function (res) {
                layer.closeAll();
                app.items = res.data;
            }
        );
    }

    layui.use(['form', 'table', 'laypage'], function () {  //如果只加载一个模块，可以不填数组。如：layui.use('form')
        var form = layui.form;//获取form模块
        var table = layui.table;
        var laypage = layui.laypage;
        laypage.render({
            elem: 'demo7'
            , count: "{$count}"  //数据总数
            , curr: 1
            , limit: 6
            , limits: [6, 12]
            , layout: ['count', 'prev', 'page', 'next', 'limit', 'skip']
            , jump: function (obj) {
                console.log(obj)
                app.curr = obj.curr;
                app.limit = obj.limit;
                init();

            }
        });

    });

    function agree(that) {
        var worker_id = $(that).attr('worker_id');
        var data_id = $(that).attr('data_id');
        var i = 0;
        app.list.forEach(function (item, index) {
            if (item == worker_id) {
                i = 1;
            }
        });
        if (i == 0) {
            app.list.push(worker_id);
            var index = layer.confirm('确认继续执行？', {
                btn: ['确定', '取消'] //按钮
            }, function () {
                $.post('{:url("bid_status")}', {id: data_id, status: 1}, function (res) {
                    if (res.code == 1) {
                        layer.msg(res.msg, {icon: 1});
                        sure();
                    }
                });
            }, function () {
                layer.close(index);
            });

        }
        else {
            layer.msg('请不要重复选择哟！');
        }
        console.log("123rtt" + worker_id);
        console.log(app.list);


    }

    function refuse(that) {
        var data_id = $(that).attr('data_id');
        var index = layer.confirm('确认继续执行？', {
            btn: ['确定', '取消'] //按钮
        }, function () {
            $.post('{:url("bid_status")}', {id: data_id, status: 2}, function (res) {
                if (res.code == 1) {
                    layer.msg(res.msg, {icon: 1});
                }
                layer.close(index);
            });
        }, function () {
            layer.close(index);
        });

    }

    function sure() {
        var w = app.list.join(',');
        console.log("zx" + w);
        $.post("{:url('bid_worker')}", {worker_id: w, id: "{$Request.param.id}"}, function (res) {
            if (res.code == 1) {
                return false;
            } else {
                layer.msg(res.msg, {icon: 2}, function () {
                });
                return false;
            }
        });

    }
</script>


</body>
</html>




